<style scoped>
.wraper {
    padding: 0 30px;
}

.search {
    padding-bottom: 20px;
}

.search span {
    color: #68777c;
    font-weight: bold;
    padding-right: 18px;
}

.search button {
    background-color: #00a8f7;
    color: #fff;
    margin-left: 8px;
}

.top {
    margin-bottom: 20px;
    border-top: 1px dashed #cccccc;
}

.detail {
    border-top: 1px dashed #cccccc;
}

.wraper .headline {
    position: relative;
    font-size: 12px;
    color: #303134;
    font-weight: bold;
    margin: 10px 0;
    line-height: 32px;
    height: 32px;
}

.wraper .add-agent {
    position: absolute;
    top: 0px;
    right: 30px;
    background-color: #348bf2;
    color: #fff;
}

.iconfont {
    font-size: 14px;
}

.red-font {
    color: #ff1f1f;
}

/* 分页 start */

/* .page {
    margin: 20px 0;
} */
.ivu-page {
    padding-bottom: 150px;
} 

/* 分页 end */

.fixed-bottom{
    padding-left: 20px;
    padding-right: 20px;
    height: 80px;
    line-height: normal !important;
    position: fixed;
    left: 210px;
    right: 0;
    bottom: 0;
    z-index: 999;
    text-align: center;
    background-color: rgb(255, 255, 255);
    box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.28);
}
.sidehide{
    left: 75px;
}

.ivu-page {
    padding-bottom: 150px;
}

</style>
<style>
.nopass{
    color: #ed3f14;
}
.pass{
    color: #19be6b;
}
.hold{
    color: #ff9900;
}

/* 自定义modal start */
.team .ivu-modal-body {
    padding: 0px;
    background-color: #fff;
}

.team .ivu-modal-content:after {
    content: '';
    display: block;
    clear: both;
}

.team .ivu-modal-content {
    zoom: 1;
    background-color: #cfeaf8;
}

.team .ivu-modal-body {
    float: left;
    width: 67%;
    padding: 10px;
}

.team .ivu-modal-footer {
    float: left;
    width: 33%;
    text-align: center;
    padding: 0 14px;
}

.team .check-info, .team .promote-info{
    margin-bottom: 10px;
    position: relative;
    min-height:195px;
}

.team .check-standard .info .title {
    width: 7.7%;
    height: 100%;
    background-color: #4074e1;
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    position: absolute;
    top: 0;
    bottom: 0; 
    overflow: hidden;
    padding-top: 5%;
    /* padding-top: 48px; */
}

.team .check-standard .promote-info.info .title {
    /* height: 425px; */
    /* padding-top: 150px; */
}

.title-div{
    /* top:50%;
    transform:translateY(50%); */
}

.team .check-standard .info .content {
    width: 92.3%;
}

.team .ivu-table-tbody {
    font-size: 12px;
}

.team .ivu-table-tbody td.condition {
    background-color: #f0f0f0;
    font-weight: bold;
    text-align: left;
    padding-left: 10px;
}

.team .ivu-table-header .condition {
    text-align: left;
    padding-left: 10px;
}

.team .ivu-table-header .ivu-table-column-center {
    background-color: #e4eaec;
    border-right: 1px solid #d6dfe2;
    border-bottom: 1px solid #d6dfe2;
}

.team .ivu-table-tbody .ivu-table-column-center {
    border-bottom: 1px solid #d6dfe2;
    border-bottom: 1px solid #d6dfe2;
}

.team .current-analyze {
    text-align: left;
    margin-bottom: 45px;
}

.team .current-analyze h5 {
    font-size: 16px;
    font-weight: bold;
    line-height: 60px;
}

.team .current-analyze .ivu-col-span-12 {
    background-color: #fff;
    height: 48px;
    line-height: 48px;
    padding-left: 20px;
    font-size: 12px;
}

.team .current-analyze .ivu-row {
    border-top: 1px solid #cfeaf8;
}

.team .current-analyze .ivu-row:first-child {
    border-top: none;
}

.team .current-analyze .ivu-col-span-12:first-child {
    border-right: 1px solid #cfeaf8;
    font-weight: bold;
}

.team .current-analyze .c1 {
    color: #ff855f;
}

.team .current-analyze .c2 {
    color: #08c111;
}


</style>



<template>
    <div class="employee-newlist">
        <product-title></product-title>
        <div class="wraper">
            <div class="search  common-box-body">
                <Row>
                    <h3 class="search-h3 huang" >
                        快速搜索
                    </h3>
                    <Form >
                        <Row>
                            <Col :xs="6" :sm="6" :md="6" :lg="6" >
                                <FormItem>
                                    <DatePicker type="month"  format="yyyy-MM" placeholder="请选择日期" :transfer="true"  @on-change="datachange($event,formdata,'search_date')"
                                        v-model="search_datetime"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col :xs="2" :sm="2" :md="2" :lg="2" offset="16">
                                <Form-item>
                                    <Button class="fr" @click='search'>查询</Button>
                                </Form-item>
                            </Col>
                        </Row>
                    </Form>
                </Row>
            </div>
            <strong class="mb20">
                更新详情:
            </strong>
            <span>
                {{synctxt}}
            </span>
            <div class="detail">
                <div class="headline">
                                
                </div>
                <div class="clearfix">
                    <div class="table-theme highlight_table">
                        <Table  ref="selection"  @on-selection-change="selectchange"  :loading="tableloading"
                        size="large"  stripe  border :columns="columns_employee" :data="data_employee"></Table>
                    </div>
                </div>  
            </div>
        </div>
        <div :class="slidetoggle?'fixed-bottom':'fixed-bottom sidehide' ">
            <Row class="pro-pagesize">
                <Col :md="24" :lg="16">
                    <Button type="success" :disabled="tableaction1" @click="syncuserinfo1" size="large" class="fl mr10">更新考核保单</Button>
                    <Button type="success" :disabled="tableaction2" @click="syncuserinfo2" size="large" class="fl mr10">批量更新考核保单</Button>
                </Col>
                <!-- <Col :md="24" :lg="8" class="tRight">
                    <Page ref="pages" :current="currentpage" :total="detailTotal" show-total show-sizer :page-size="pagesize" @on-change="pageChange" @on-page-size-change="pageSizeChange" placement="top" class="page"></Page>
                </Col> -->
            </Row>
        </div>

    </div>
</template>

<script>
import productTitle from '../../components/productTitle'
import {get_policys,change_policy} from '../../api/org'
export default {
    data() {
        var year = new Date().getFullYear()
        var month=month>10?new Date().getMonth()+1:'0'+(new Date().getMonth()+1);
            // this.formdata.search_date=year+'-'+month;
        return {
            tableloading:true,
            synctxt:'',
            currents:0,
            policy_mid:"",
            policy_mids:[],

            tableaction1:true,//批量转正的按钮
            tableaction2:true,//批量转正的按钮
            currentpage:1,
            search_datetime:"",
            formdata:{
                search_date:year+'-'+month,
            },
            org:{ 
                dateall:"",
                date:"",
                id:[],
                },
            cou:-1,
            reachPromote:true, //是升还是降级
            checkModal:false,
            closeable: false,
            loading: true,
            tableloading:true,
            currentRow:{},
            page: 1,
            pagesize: 10,
            detailTotal: 0,
            columns_employee: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '保单号',
                    key: 'policy_num',
                    align: 'center',
                },
                {
                    title: '投保单号',
                    key: 'insure_num',
                    align: 'center',
                },
                {
                    title: '保险公司',
                    key: 'cname',
                    align: 'center',
                },
                {
                    title: '承保时间',
                    key: 'underwrite_date',
                    align: 'center',
                },
                {
                    title: '代理人',
                    key: 'agent',
                    align: 'center',
                    render: (h, params) => {                                               
                        return h('div', {
                        },params.row.agent.name);
                    }
                },
                {
                    title: '是否已更新',
                    key: 'is_changed',
                    align: 'center',
                    render: (h, params) => {                                               
                        return h('div', {
                            attrs:{
                                class:(params.row.is_changed == '1') ? 'pass' :'nopass' ,
                            },
                        },params.row.is_changed=='1'?'已更新' :'未更新');
                        
                    }
                },
            ],
            data_employee: [],
            ruleValidate: {
                dateall:[
                    { required: true, message: '日期不能为空' }
                ],
            },
        }
    },
    components: {
        productTitle
    },
    computed: {
        slidetoggle(){
            return this.$store.state.sildeshow
        },
    },
    created() {
        this.getList()   
    },
    methods: {
        selectchange(val){
            var _this = this;
            if(val.length==1){
                _this.tableaction1=false;
                _this.tableaction2=true;
                _this.policy_mid = val[0]._id.$id;
                console.log(_this.policy_mid,"_this.policy_mid.......")
            }else if(val.length>1){
                _this.tableaction1=true;
                _this.tableaction2=false;
                _this.policy_mids=[];
                for(var i in val){
                    if(!_this.policy_mids.includes(val[i]._id.$id)){
                        _this.policy_mids.push(val[i]._id.$id)
                    }
                }
            }else{
                _this.tableaction1=true;
                _this.tableaction2=true;
            }
        },
        //时间转换
        datachange(date,obj,param){
            obj[param] = date;
            console.log(obj[param],"当前点击的是哪个日期")
        },
        // 转正
        positive(){
            var _this = this;
            _this.showAddModal2 = true;
        },
        //批量转正
        positiveall(){
            var _this = this;
             _this.showAddModal2 = true;
        },
        syncuserinfo2(){
            this.tableaction1=true;
            this.tableaction2=true;
            console.log("批量更新")
            let _userlistasc = this.policy_mids
            
            if(_userlistasc.length > 0){
                this.syncinfofor(_userlistasc)
            }else{
                this.$Message.error('数据异常');
            }
        },
        syncinfofor(_userlistasc){
            let _length = _userlistasc.length
            for(var i=0;i<this.policy_mids.length;i++){
                var  _params = {
                    policy_mid : this.policy_mids[i]
                }
                new Promise((resolve, reject) => {
                    change_policy(_params).then(response => {
                        console.log(_params,"_params..........")
                        if(response.data.err == 0){
                            this.currents++
                            this.synctxt = '同步员工数据：'+this.currents+'/'+_length+'已完成更新'
                            if(this.currents>=_length){
                                this.synctxt = '同步员工数据：已完成所有的选中更新' 
                                this.getList();
                                return   
                            }
                        } else {
                            this.$Message.error(response.data.info);
                        }                       
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
          }
        },
        syncuserinfo1(){
            this.tableaction1=true;
            this.tableaction2=true;
             console.log("单个更新")
            let _userlistasc = this.policy_mid
            console.log(_userlistasc,"ceshi ")
            if(_userlistasc.length > 0){
                this.syncinfo(_userlistasc)
            }else{
                this.$Message.error('员工数据异常');
            }
        },
        //同步员工数据
        syncinfo(_userlistasc){
            let _length = _userlistasc.length
            // if(this.currents >=_userlistasc.length){
            //     console.log("ok")
            //     this.synctxt = '同步员工数据：已完成全部更新'
            //     this.currents = 0
                
            //     console.log("okok")
            //     return;  
            // }
            let _params = {
                policy_mid : this.policy_mid
            }
            console.log(_params,"_parmsa")
            new Promise((resolve, reject) => {
                change_policy(_params).then(response => {
                    if(response.data.err == 0){
                        this.currents++
                        this.synctxt = '同步员工数据：本条数据已完成更新'
                        this.getList();
                        // this.syncinfo(_userlistasc)
                    } else {
                        this.$Message.error(response.data.info);
                    }                       
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },




    
        // 搜索
        search() {
            this.getList()
            // this.tableloading = true;
            // this.tableaction1 = true;
            // this.tableaction1 = true;
            // this.search_datetime = this.formdata.search_date
            // console.log(this.formdata,"canshu");
            // new Promise((resolve, reject) => {
            //     get_policys(this.formdata).then(response => {
            //         console.log(response.data);
            //         this.tableloading = false
            //         if (response.data.err == 0) {
            //             this.data_employee = response.data.data;
            //         } else {
            //             this.$Message.error(response.data.info);
            //         }
            //         resolve();
            //     }).catch(error => {
            //         this.tableloading = false
            //         reject(error);
            //     });
            // });          
        },
        // 获取员工列表
        getList() {
            this.tableloading=true;
            this.tableaction1 = true;
            this.tableaction1 = true;
            // var year = new Date().getFullYear()
            // var month=month>10?new Date().getMonth()+1:'0'+(new Date().getMonth()+1);
            // this.formdata.search_date=year+'-'+month;
            this.search_datetime = this.formdata.search_date
            console.log(this.formdata,"canshu");
            new Promise((resolve, reject) => {
                get_policys(this.formdata).then(response => {
                    console.log(response.data);
                    this.tableloading = false
                    if (response.data.err == 0) {
                        this.data_employee = JSON.parse(JSON.stringify(response.data.data));
                        // this.detailTotal = response.data.data.total;
                        this.search_datetime = this.formdata.search_date
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    this.tableloading = false
                    reject(error);
                });
            });
        },
        // 页码改变
        pageChange(page) {
            this.page = page
            this.getList()
        },
        // 每页条数改变
        pageSizeChange(pagesize) {
            this.pagesize = pagesize
            this.getList();
        },
    }
}
</script>
